{$contents}

{literal}
<div style="text-align:left; padding:10px;">

Setting up image manager is very simple. 
To add imageManager button add imageManagerUrl param to htmlEditor. 
This param value should be URL to you controller method that shows list of images (or what ever else) that pops up when user clicks on imageManager button.<br />
<br />
In popup use javascript method updateHtmlEditorImage(newElementId,imageUrl) to update content in html editor. 

<h2>Source</h2>
<pre class="code">
&lt;?php
$panel = array(
	'title' => 'Html editor images',
	'layout' => 'table',
	'layoutConfig' => array(
		'columns' => 2,
	),
	'style' => 'width:700px',
	'action' => $this->getUrl('htmlEditorImages'),
	'items' => array(
		$message,
		array(
			'type' => 'htmlEditor',
			'title' => 'Editor',
			'name' => 'text',
			'imageManagerUrl' => $this->getUrl('htmlImagesHandler'),
		),
	),
	'buttons' => array(
		array(
			'type' => 'button',
			'title' => 'Save',
			'name' => 'save',
		),
	),	
);
$this->view->contents = DomFg::render( $panel );
?&gt;
</pre>


<h2>Simple manager list</h2>
<pre class="code">
&lt;?php
if( $_GET['delete'] && $item = HtmlEditorImage::load( $_GET['delete'] )){
	$item->delete();
}
				
$source = new DomArDataSource( HtmlEditorImage::query()->orderBy('t.name DESC'), 40 );

function addHandler( $row ) {
	return '&lt;a href="javascript:updateHtmlEditorImage('.$row->id.',\''.$row->image->getUrl().'\');"&gt;Use&lt;/a&gt;';
}

$panel = array(
	'title' => 'Images',
	'layout' => 'table',
	'layoutConfig' => array(
		'columns' => 1,
	),
	'items' => array(
		array(
			'type' => 'button',
			'title' => 'Lisa uus',
			'link' => $this->getUrl('htmlImagesEdit/'),
		),
		array(
			'type' => 'grid',
			'source' => $source,
			'fields' => array(
				array('key' => 'name', 'title' => 'Nimi'),
				array('handler'=>'addHandler','title' => 'Valikud','colspan' => 3),
				array('type' => 'gridButton', 'value' => 'Muuda', 'link' => $this->getUrl('htmlImagesEdit/')),
				array('type' => 'gridButton', 'value' => 'Kustuta', 'link' => $this->getUrl('htmlImagesHandler/&delete='), 'confirmMessage' => 'Are you sure?' ),
			),
		),
	),
);

$this->view->contents = DomFg::render( $panel );
?&gt;
</pre>

<h2>Simple manager edit/ add new</h2>
<pre class="code">
&lt;?php
$new = $id == 0;
$item = $new ? new HtmlEditorImage() : HtmlEditorImage::load($id);
		
$post = DomFgPost::getInstance();

if( $post->save ) {
	
	$item->name = $post->name;
	$item->image->addUploaded( $post->image[0], $post->image[1]);
	
	if( $item->save() ) {
		$id = $item->id;
		$message = array('type' => 'ok','colspan' => 3,'message' => 'Salvestatud',);
	} else {
		$message = array('message' => 'Tekkinud on viga!','type' => 'ok','colspan' => 3,'description' => implode('<br>',$item->getValidationReport()->messages),);
	}
}
		
$panel = array(
	'title' => 'Image',
	'layout' => 'table',
	'action' => $this->getUrl('htmlImagesEdit/'.$id),
	'layoutConfig' => array(
		'columns' => 3,
		'columnWidths' => array( 100 ),
	),
	'items' => array(
		$message ,
		array(
			'type' => 'image',	
			'src' => $item->icon->getUrl(),
			'rowspan' => 2,
			'style' => 'width:100px; height:100px;'
		),
		array(
			'type' => 'textField',
			'title' => 'Nimi',
			'value' => $item->name,
			'name' => 'name',
		),
		array(
			'type' => 'file',
			'title' => 'File',
			'name' => 'image',
		),
	),
	'buttons' => array(
		array(
			'title' => 'Salvesta',
			'name' => 'save'
		),
		array(
			'title' => 'Back',
			'link' => $this->getUrl('htmlImagesHandler'),
			'style' => 'float:left',
		),
	),
);
		
$this->view->contents = DomFg::render( $panel );
?&gt;
</pre>

</div>
{/literal}